package cn.com.css.taxInspection.attention.service.impl;

import cn.com.css.taxInspection.attention.entity.JtjbEntity;
import cn.com.css.taxInspection.attention.mapper.JtjbMapper;
import cn.com.css.taxInspection.attention.service.JtjbService;
import cn.com.css.taxInspection.common.constants.Constants;
import cn.com.css.taxInspection.gt3.service.DmGySwryService;
import cn.com.css.taxInspection.system.service.impl.HttpSessionService;
import cn.com.css.taxInspection.util.DateUtils;
import cn.com.css.taxInspection.util.TsBqUtils;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("JtjbService")
public class JtjbServiceImpl extends ServiceImpl<JtjbMapper, JtjbEntity> implements JtjbService {

    @Autowired
    private JtjbService jtjbService;
    @Autowired
    private HttpSessionService httpSessionService;
    @Autowired
    private DmGySwryService dmGySwryService;

    @Override
    @DS("oracle")
    public Boolean saveJtjb(JtjbEntity jtjbEntity) {
        boolean result;
        String userID = httpSessionService.getCurrentUserId();

        if (TsBqUtils.isNull(jtjbEntity.getUuid())) {
            jtjbEntity.setUuid(TsBqUtils.getUUID());
            jtjbEntity.setLrrq(DateUtils.getCurrentDate());
            jtjbEntity.setYxbz(Constants.AJZT_LX_Y);
            jtjbEntity.setLrrxm(userID + " | " + dmGySwryService.getSwry(userID).getSwryxm());
            result = jtjbService.save(jtjbEntity);
        } else {
            jtjbEntity.setXgrq(DateUtils.getCurrentDate());
            jtjbEntity.setLrrxm(userID + " | " + dmGySwryService.getSwry(userID).getSwryxm());
            result = jtjbService.updateById(jtjbEntity);
        }
        return result;
    }
}